#
# This file is a part of the open-eBackup project.
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
# If a copy of the MPL was not distributed with this file, You can obtain one at
# http://mozilla.org/MPL/2.0/.
#
# Copyright (c) [2024] Huawei Technologies Co.,Ltd.
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#

import sys

from common.common import exter_attack
from common.const import SysData
from exchange import log
from exchange.backup.backup_base.base_exchange_allow_backup_in_local_node import ExchangeBackupAllowBackupInLocalNode
from exchange.commons.exchange_exception import ExchangeErrCodeException


class DagAllowBackupInLocalNode(ExchangeBackupAllowBackupInLocalNode):
    def __init__(self, pid):
        super().__init__(pid)
        self._pid = pid


@exter_attack
def do_exec(pid):
    try:
        job = DagAllowBackupInLocalNode(pid)
        job.do_allow_backup_in_local_node_task(job.get_job_info())
    except ExchangeErrCodeException as err_str:
        log.error(f"Post backup failed, err: {err_str}, pid:{pid}")
        return False
    return True

if __name__ == '__main__':
    for line in sys.stdin:
        SysData.SYS_STDIN = line
        break

    if len(sys.argv) < 1:
        log.error("Param is wrong.")
        sys.exit(1)
    pid_args2 = sys.argv[1]
    try:
        do_exec(pid_args2)
    except Exception as err:
        log.error(f"Err: {err}, pid: {pid_args2}")
        sys.exit(0)

    sys.exit(0)